<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function Star(uname, age) {
            this.uname = uname
            this.age = age
            // this.sing =function () {
            //     console.log('唱歌');
            // }
        }
        var that;
        Star.prototype.sing = function () {
            console.log('唱歌');
            that = this
        }
        var ldh = new Star('刘德华', 18)
        //   1.在构造函数里的this指向的是对象实例ldh
        ldh.sing()
        console.log(ldh === that);
    //   2.在原型对象里的this指向的是实例对象 ldh
    //   只有函数被调用了this才能确定指向 一般情况下都指向调用函数的实例对象
    </script>
</body>

</html>